package components

import (
	"eino-script/engine/entity"
	"eino-script/engine/types"
	"fmt"
)

func CreateGeneralNode(cfg *entity.Node) (*types.Node, error) {
	node := &types.Node{}
	node.Node = *cfg
	return node, nil
}

type StartNode struct {
	types.Node
}

func CreateStartNode(cfg *entity.Node) (types.NodeInterface, error) {
	n, err := CreateGeneralNode(cfg)
	if err != nil {
		return nil, err
	}
	node := &StartNode{
		Node: *n,
	}
	return node, nil
}

func (s StartNode) Id() string {
	return s.Node.Id
}

func (s StartNode) Type() (entity.NodeType, error) {
	return s.Node.Type, nil
}

func (s *StartNode) GetSourceId() (string, error) {
	return string(s.Node.Type), nil
}

func (s *StartNode) GetTargetId() (string, error) {
	return "", fmt.Errorf("开始节点没有输入句柄")
}

type EndNode struct {
	types.Node
}

func CreateEndNode(cfg *entity.Node) (types.NodeInterface, error) {
	n, err := CreateGeneralNode(cfg)
	if err != nil {
		return nil, err
	}
	node := &EndNode{
		Node: *n,
	}
	return node, nil
}

func (e EndNode) Id() string {
	return e.Node.Id
}

func (e EndNode) Type() (entity.NodeType, error) {
	return e.Node.Type, nil
}

func (e EndNode) GetSourceId() (string, error) {
	return "", fmt.Errorf("结束节点没有输出句柄")
}

func (e EndNode) GetTargetId() (string, error) {
	return string(e.Node.Type), nil
}
